import re
import datetime
import time


def get_say():
    # 根据当前时间，返回打招呼语句
    now_hour = time.localtime(time.time()).tm_hour
    if 5 <= now_hour < 11:
        say = '早上好呀~\n'
    elif 11 <= now_hour < 14:
        say = '中午好呀~\n'
    elif 14 <= now_hour < 19:
        say = '下午好呀~\n'
    else:
        say = '晚上好呀~\n'
    return say


def current_expect_time(expect_time):
    # 目标时间减去当前时间

    # 获取目标时间戳
    expect_time = "".join(re.findall(r"[0-9]", expect_time))
    expect_time_stamp = time.mktime(time.strptime(expect_time, '%Y%m%d%H%M%S'))

    # 获取当前时间戳
    now_time = time.time()

    # 当前时间减去预期时间 返回单位：s
    total_s = now_time - expect_time_stamp

    return total_s


def get_love_total_duration(expect_time):
    # 返回恋爱xx天xx小时
    total_s = current_expect_time(expect_time)

    # 天数
    total_d = total_s / 60 / 60 / 24

    number_dec = 24 * float("0." + str(total_d).split(".")[1][0:4])

    return int(total_d), int(number_dec)


#  计算还有多少天生日(生日\今天\生日月\生日天)
def get_birthday_days(expect_time):
    num = None
    st = "".join(re.findall(r"[0-9]", expect_time))
    today, mon, day = st[0:4], st[4:6], st[6:8]
    print(today, mon, day)
    toyear = time.strftime('%Y', time.localtime(time.time()))
    tomon = time.strftime('%m', time.localtime(time.time()))
    todayy = time.strftime('%d', time.localtime(time.time()))
    toyear = int(toyear)
    tomon = int(tomon)
    todayy = int(todayy)

    #  年月日合起来
    today = time.strftime("%Y-%m-%d", time.localtime())

    try:
        # 明年的今天
        next_year = int(toyear) + 1
        str3 = str(next_year) + "-" + str(mon) + "-" + str(day)
        str4 = str(int(toyear)) + "-" + str(mon) + "-" + str(day)
        date2 = datetime.datetime.strptime(today[0:10], "%Y-%m-%d")  # 今天
        date3 = datetime.datetime.strptime(str3[0:10], "%Y-%m-%d")  # 明年生日=今年年份+1 +生日的月日
        date4 = datetime.datetime.strptime(str4[0:10], "%Y-%m-%d")  # 今年的年+生日的月日
        num = 0

        #  明年
        #  今天过生日:月日相等
        if mon == tomon:
            if day == todayy:
                print("今天过生日,祝你生日快乐")
                num = 0
            if int(day) > todayy:
                print("这个月过生日")
                num = (date4 - date2).days

            if int(day) < todayy:
                print("生日这个月已经过了")
                num = (date3 - date2).days
        #  已经过了生日的:明年生日-今天
        elif int(mon) < tomon:
            print("今年生日已经过了")
            num = (date3 - date2).days
        #  还没过生日:今年的年+生日的月日  -  今天的年月日
        else:
            print("今年的生日还没到")
            num = (date4 - date2).days  # 返回的全部是非0的整数
    except ValueError as e:
        print("请输入正确的日期，一个月只有适合的天数 " + str(e))
        print("程序结束...")
    return str(num)


if __name__ == "__main__":

    num = get_birthday_days("2000-08-30 00:00:00")
    if num != 0:
        print("距离生日还有" + str(num) + "天")